package com.example.leetcode;

import org.junit.jupiter.api.Test;

import java.util.Stack;

public class LeetCode25 {
    public class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
        }
        // 添加新的结点
        public void add(int newval) {
            ListNode newNode = new ListNode(newval);
            if(this.next == null)
                this.next = newNode;
            else
                this.next.add(newval);
        }
    }

    @Test
    public void Test() {
        ListNode l1=new ListNode(1);
        l1.add(2);
        l1.add(4);
        ListNode l2=new ListNode(1);
        l2.add(3);
        l2.add(4);
        ListNode dum = new ListNode(0), cur = dum;
        while(l1 != null && l2 != null) {
            if(l1.val < l2.val) {
                cur.next = l1;
                l1 = l1.next;
            }
            else {
                cur.next = l2;
                l2 = l2.next;
            }
            cur = cur.next;
        }
        cur.next = l1 != null ? l1 : l2;

        System.out.println(dum.next);
    }



}
